//
//  LSRetweetView.swift
//  新浪微博---01次
//
//  Created by 李宗帅 on 16/5/7.
//  Copyright © 2016年 LS. All rights reserved.
//

import UIKit
import SnapKit
class LSRetweetView: UIView {
    
    var bottomConstrain:Constraint?

    var retweetViewModel: LSStatusViewModel? {
        didSet {
//            contentLabel.text = retweetViewModel?.retweet_String
            //让转发微博能够正常显示表情
            contentLabel.attributedText = retweetViewModel?.dealAttributeString(retweetViewModel?.retweet_String)
            
            
            //存在约束冲突,所以再添加约束的时候,把以前的卸载一下
            bottomConstrain?.uninstall()
            
            if let count = retweetViewModel?.retweet_pic_urls?.count where count == 0 {
                
                picView.hidden = true
                //没有配图
                self.snp_updateConstraints(closure: { (make) -> Void in
                    bottomConstrain = make.bottom.equalTo(contentLabel).constraint
                })
                
                
            } else {
                picView.hidden = false

                //有配图
                self.snp_updateConstraints(closure: { (make) -> Void in
                    bottomConstrain = make.bottom.equalTo(picView.snp_bottom).constraint
                })
                
                picView.pic_urls = retweetViewModel?.retweet_pic_urls
            }
                       
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI(){
        
        addSubview(contentLabel)
        addSubview(picView)
        
        contentLabel.text = "转发微博是kid了开始就打开"
        
        contentLabel.snp_makeConstraints { (make) -> Void in
            make.left.right.top.equalTo(self)
        }
        
        picView.snp_makeConstraints { (make) -> Void in
            
            make.left.equalTo(self)
            
            make.top.equalTo(contentLabel.snp_bottom)
            
//            make.width.height.equalTo(100)
        }
        
        self.snp_makeConstraints { (make) -> Void in
            
            bottomConstrain = make.bottom.equalTo(picView.snp_bottom).constraint
        }
        
    }

    
    //MARK:--懒加载
    //内容
    private lazy var contentLabel:UILabel = UILabel(size: 16, color: UIColor.lightGrayColor(), singleLine: false)
    
    private lazy var picView:LSPhotoView = LSPhotoView()
    
    
}
